<?php

declare(strict_types=1);
/**
 * This file is part of bearing-web.
 *
 * @link     https://www.bearing.cn/
 * @contact  tech@bearing.cn
 * @license  https://gitee.com/cppo/bearing_web/-/blob/master/README.md
 */

namespace frontend\controllers;

use common\models\UserModel;
use frontend\logics\UsersLogic;
use yii\db\Exception;

class UsersController extends BaseController
{
    public $modelClass = 'common\models\UserModel';

    /**
     * @throws Exception
     */
    public function actionLogin(): array
    {
        $params = \Yii::$app->request->post();
        $ret = UsersLogic::login($params);
        if ($ret === false) {
            \Yii::$app->response->setStatusCode(500, UsersLogic::getError(0));
            return [];
        }
        return $ret;
    }

    /**
     * @throws Exception
     */
    public function actionRegister(): array
    {
        $params = \Yii::$app->request->post();
        $ret = UsersLogic::register($params);
        if ($ret === false) {
            \Yii::$app->response->setStatusCode(500, UsersLogic::getError(0));
        }
        return [];
    }
}
